using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using NHibernate.Data.Managers;
using NHibernate.Data.Models;
using NHibernate.Data.Base;

namespace NHibernate.Data.UnitTests
{
	[TestFixture]
    public partial class WineTests : UNuitTestBase
    {
        protected IWineManager manager;
		
		public WineTests()
        {
            manager = managerFactory.GetWineManager();
        }
		
		protected Wine CreateNewWine()
		{
			Wine entity = new Wine();
			
			// You may need to maually enter this key if there is a constraint violation.
			entity.Id = default(Int64);
			
			entity.OriginCountry = default(Int64);
			entity.Brand = default(Int64);
			entity.RegionC = default(Int64);
			entity.TypeBySugar = default(Int64);
			entity.AdditionalInformation = default(Int64);
			entity.RegionA = default(Int64);
			entity.LocalName = default(Int64);
			entity.RegionB = default(Int64);
			entity.GeneralAgentInMainlandChina = default(Int64);
			entity.OakAging = default(Int64);
			entity.Winery = default(Int64);
			entity.ClosureType = default(Int64);
			entity.TypeByColor = default(Int64);
			entity.Classification = default(Int64);
			entity.WineTypeByVinification = default(Int64);
			entity.Supplier = default(Int64);
			entity.Description = default(Int64);
			entity.MakerComment = default(Int64);
			entity.Code = "Test Test Te";
			entity.InternationalName = "Test Test ";
			entity.Vintage = "Tes";
			entity.IsSparklingWine = true;
			entity.IsFineWine = true;
			entity.Alcohol = 28;
			entity.Volume = 92;
			entity.ShelfLife = 10;
			entity.BottlingDate = DateTime.Now;
			entity.MarketPrice = 10;
			entity.RetailPrice = 76;
			entity.MemberPrice = 93;
			entity.VIPPrice = 4;
			entity.PromotionalPrice = 74;
			entity.RecommendationIndex = 2;
			entity.Packing = 72;
			entity.ServingTemperature = "Test Test Test Test Test Test ";
			entity.ServingTime = "Test Test ";
			entity.DecanterDuration = "Test Te";
			entity.Sugar = "Test Test Test Test T";
			entity.Weight = 40;
			entity.MakerName = "Test Test";
			entity.MemberScoring = 98;
			entity.AgingDuration = "Test Test Test Test Test T";
			entity.IsWineryBottling = true;
			entity.IsBrailleLogo = true;
			entity.IsManualHarvest = true;
			entity.AnnualProduction = default(Int64);
			entity.Barcode = "Test";
			entity.IsOrganicProduct = true;
			entity.ImportationDeclarationNo = "Test Test Test Test ";
			entity.CIQNo = "Test ";
			entity.MinimumOrderQuantity = default(Int64);
			entity.ImageA = "Test Test ";
			entity.ImageB = "Test Test ";
			entity.ImageC = "Test Test ";
			entity.ImageD = "Test Test ";
			entity.Resource = "Test Tes";
			
			return entity;
		}
		protected Wine GetFirstWine()
        {
            IList<Wine> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				Wine entity = CreateNewWine();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                Wine entityA = CreateNewWine();
				manager.Save(entityA);

                Wine entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                Wine entityA = GetFirstWine();
				entityA.OriginCountry = default(Int64);
				
				manager.Update(entityA);

                Wine entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.OriginCountry, entityB.OriginCountry);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                Wine entity = GetFirstWine();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}